const { reactive, createApp, onMounted } = Vue;
//import GlobalFilters from '../static/js/vue_plug/globalFilters.js';

var app = createApp({
    setup() {
        const v_data = reactive({
            post_data: {
                name: "",
                pageindex: 1,
                pagesize: 20,
            },
            ext_data: {
            },
            result: {
                total: 0,
                rows: []
            },
        });

        onMounted(async () => {
            await methods.initPage();
            await methods.loadData();
            await methods.dealData();
        });
        const methods = {

            //业务函数
            initPage: async () => {
            },
            loadData: async () => {
                await methods.getListData();
            },
            getListData: async (pageindex) => {
                if (pageindex !== undefined) {
                    v_data.post_data.pageindex = pageindex;
                }
                const url = ApiHost + "/[subFolder]/[tblName]list";
                const result = await post(url, v_data.post_data);
                if (result.statecode == 0) {
                    v_data.result = result.data;
                } else {
                    layerMsg("应用错误：" + result.message);
                }
            },
            dealData: () => {
                pagerByVM();
            },

            //popup函数
            popupAdd: () => {
                const url = PageHost + "/[subFolder]/[tblName]edit?id=0";
                openLayer(url, "新增");
            },
            popupEdit: (item) => {
                const url = PageHost + "/[subFolder]/[tblName]edit?id=" + item.id;
                openLayer(url, "修改");
            },
            popupView: (item) => {
                const url = PageHost + "/[subFolder]/[tblName]view?id=" + item.id;
                openLayer(url, "查看详情");
            },
            popupDelete: (item) => {
                layerConfirm("确定要删除此记录吗？删除后不可恢复！", async () => {
                    const url = ApiHost + "/[subFolder]/[tblName]delete";
                    const result = await post(url, { id: item.id });
                    const code = result.statecode;
                    if (code === 0) {
                        methods.layerCallBack();
                    } else {
                        layerAlert("提交失败：" + result.message);
                    }

                });
            },
            //其它
            layerCallBack: () => {
                setTimeout(() => {
					methods.loadData();
                }, 200);
            }
        };
        return { d: v_data, ...methods };

    }
});

//app.use(GlobalFilters);
VM = app.mount('#app');






